package com.wyl.netty.client;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import com.wyl.netty.common.protobuf.MessageModule;
import com.wyl.netty.common.execute.MessageTask4Response;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
 * @author: wyl
 * @date: 2021/7/13
 * @des: client处理器
 */
public class ClientHandler extends ChannelInboundHandlerAdapter {

    /**
     * 创建线程池
     */
    ThreadPoolExecutor workerPool = new ThreadPoolExecutor(5,
            10,
            60L,
            TimeUnit.SECONDS,
            new ArrayBlockingQueue<>(4000),
            new ThreadPoolExecutor.DiscardPolicy());


    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        MessageModule.Message response = (MessageModule.Message) msg;
        // 异步处理
        workerPool.submit(new MessageTask4Response(response, ctx));
    }

}
